def solution(n: int, m: int, s: str, c: str) -> int:
    # PLEASE DO NOT MODIFY THE FUNCTION SIGNATURE
    # write code here
    kinds_num = {}
    for k in s:
        kinds_num[k] = kinds_num.get(k, 0) + 1

    kinds_user = {}
    for k in c:
        kinds_user[k] = kinds_user.get(k, 0) + 1

    buy_numbers = 0
    for k in kinds_num:
        if k not in kinds_user:
            continue
        if kinds_user[k] < kinds_num[k]:
            buy_numbers += kinds_user[k]
        else:
            buy_numbers += kinds_num[k]


    return buy_numbers

if __name__ == '__main__':
    print(solution(3, 4, "abc", "abcd") == 3)
    print(solution(4, 2, "abbc", "bb") == 2)
    print(solution(5, 4, "bcdea", "abcd") == 4)